package zjitc.list;

public class MyArrayList<E> implements MyList<E> {
    private Object[]arr=new Object[10];
    private int size=0;
    @Override
    public boolean add(E data) {
        if (size>=arr.length){
            Object[]temp=new Object[size*3];
            for (int i=0;i<size;i++){
                temp[i]=arr[i];
            }
            arr=temp;
        }
        arr[size]=data;
        size++;
        return true;
    }

    @Override
    public boolean add(int index, E data) {
        if (index <0 || index >size){
            throw new RuntimeException("MyArrayList数组越界");
        }
        //如何扩容
        capacity();
        //扩容后怎么插入
        for (int i=size;i>index;i--){
            arr[i]=arr[i-1];
        }
        arr[index]=data;
        size++;
        return false;
    }

    @Override
    public E remove(E data) {
        return null;
    }

    @Override
    public E remove(int index) {
        return null;
    }

    @Override
    public boolean set(int index, E data) {
        return false;
    }

    @Override
    public E getValue(int index) {
        return null;
    }

    @Override
    public int size() {
        return 0;
    }
    private void capacity(){
        if (size>=arr.length){
            Object[]temp=new Object[size*3];
            for (int i=0;i<size;i++){
                temp[i]=arr[i];
            }
            arr=temp;
        }
    }
}
